#!/bin/bash

trap 'echo "脚本已退出，拜~"; exit' INT

echo "当前时间 （$date）"

echo "这是适用于armbian、Ubuntu的换源脚本
1.清华源（最高23.04）
2.阿里源（最高24.04）
3.退出
"

read -p "请输入你想要的源的数字（1-3）:" yuan  

if [ "$yuan" = "1" ]; then
    echo "只写数字就行，如23.04
    23.04(lunar)
    22.10(kinetic)
    22.04(jammy)
    20.04[LTS (focal)]
    18.04[LTS (bionic)]
    16.04[LTS (xenial) (EOL)]
    14.04[LTS (trusty) (EOL)]"

read -p "请输入你想要的版本的数字:" banben
    fi
    if [ "$banben" = "23.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"      
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ lunar-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ lunar-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "22.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"  
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "22.10" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"    
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ kinetic-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ kinetic-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ kinetic-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "20.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"   
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ focal-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "18.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址" 
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ bionic-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "16.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ xenial-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ xenial-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$banben" = "14.04" ]; then
         echo "你选择了清华源 $banben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入清华大学开源软件镜像站的源地址"
         echo "# 默认注释了源码镜像以提高 apt update 速度，如有需要可自行取消注释
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-updates main restricted universe multiverse
         deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse
         # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-backports main restricted universe multiverse

         deb http://security.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse
         # deb-src http://security.ubuntu.com/ubuntu/ trusty-security main restricted universe multiverse

         # 预发布软件源，不建议启用
         # deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
         # # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ trusty-proposed main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
elif [ "$yuan" = "2" ]; then
         echo "
         只填数字就行,如24.04
         24.04(noble)
         23.04(lunar)
         22.04(jammy)
         20.04[LTS (focal)]
         18.04[LTS (bionic)]
         16.04[LTS (xenial) (EOL)]
         14.04[LTS (trusty) (EOL)]
"
read -p "请输入你想要的版本的数字:" abanben
    if [ "$abanben" = "24.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入阿里云开源软件镜像站的源地址"
         echo "deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$abanben" = "23.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
        
         echo "写入阿里云开源软件镜像站的源地址"
         echo "deb https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
        sudo apt update
    elif [ "$abanben" = "22.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

         echo "写入阿里云开源软件镜像站的源地址"
          echo "deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$abanben" = "20.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

         echo "写入阿里云开源软件镜像站的源地址"
         echo "deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$abanben" = "18.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "写入阿里云开源软件镜像站的源地址"
         echo "deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$abanben" = "16.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
         echo "deb https://mirrors.aliyun.com/ubuntu/ xenial main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial main

deb https://mirrors.aliyun.com/ubuntu/ xenial-updates main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates main

deb https://mirrors.aliyun.com/ubuntu/ xenial universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial universe
deb https://mirrors.aliyun.com/ubuntu/ xenial-updates universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-updates universe

deb https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security main
deb https://mirrors.aliyun.com/ubuntu/ xenial-security universe
deb-src https://mirrors.aliyun.com/ubuntu/ xenial-security universe
" > /etc/apt/sources.list
         echo "更新包列表信息"
         sudo apt update
    elif [ "$abanben" = "14.04" ]; then
         echo "你选择了阿里源 $abanben 版本，正在备份当前的 sources.list 文件..."
         sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak
        
         echo "写入阿里云开源软件镜像站的源地址"
         echo "deb https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty main restricted universe multiverse
deb https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-updates main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ trusty-backports main restricted universe multiverse

## Not recommended
# deb https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ trusty-proposed main restricted universe multiverse
" > /etc/apt/sources.list
     fi
elif [ "$yuan" = "3" ]; then
      echo "好的，已退出"
      exit
else
      echo "请输入正确的版本数字"
      exit 1
    fi
echo "脚本执行结束，感谢你的使用
      编写作者：Yalishidoorde"
exit